package com.ruoyi.work.service.impl;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.work.domain.WorkDeclarer;
import com.ruoyi.work.mapper.WorkDeclarerMapper;
import com.ruoyi.work.service.IWorkDeclarerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: MMDZ
 * @Desc:
 */
@Service
public class WorkDeclarerServiceImpl implements IWorkDeclarerService {

    @Autowired
    private WorkDeclarerMapper workDeclarerMapper;

    /**
     * 查询人员项目配置列表 - 条件 分页
     *
     * @param declarer
     * @return
     */
    @Override
    public List<WorkDeclarer> selectWorkDeclarerList(WorkDeclarer declarer) {
        return workDeclarerMapper.selectWorkDeclarerList(declarer);
    }

    /**
     * 查询没有加入的人员项目配置的人员
     *
     * @param declarer
     * @return
     */
    @Override
    public List<WorkDeclarer> selectWorkDeclarerUnselected(WorkDeclarer declarer) {
        return workDeclarerMapper.selectWorkDeclarerUnselected(declarer);
    }

    /**
     * 根据id查询人员项目配置
     *
     * @param declarerId
     * @return
     */
    @Override
    public WorkDeclarer selectDeclarerById(Long declarerId) {
        return workDeclarerMapper.selectDeclarerById(declarerId);
    }

    /**
     * 查询人员是否在项目配置中
     *
     * @param userId
     * @return
     */
    @Override
    public Boolean selectExistDeclarer(Long userId) {
        return workDeclarerMapper.selectExistDeclarer(userId) > 0;
    }

    /**
     * 新增
     *
     * @param userIds
     * @return
     */
    @Override
    public int insertWorkDeclarerByIds(Long[] userIds) {
        if (StringUtils.isEmpty(userIds))
            throw new ServiceException("获取申报人员ID信息异常，请联系管理员", HttpStatus.ERROR);
        return workDeclarerMapper.insertWorkDeclarerByIds(userIds);
    }

    /**
     * 修改
     *
     * @param workDeclarer
     * @return
     */
    @Override
    public int updateDeclarer(WorkDeclarer workDeclarer) {
        return workDeclarerMapper.updateDeclarer(workDeclarer);
    }

    /**
     * 删除
     *
     * @param declarerId
     * @return
     */
    @Override
    public int deleteWorkDeclarerById(Long declarerId) {
        return workDeclarerMapper.deleteWorkDeclarerById(declarerId);
    }
}
